﻿using AutoMapper;
using Traceability_2203.Bais.Api.Application.Commands.User;
using Traceability_2203.Bais.Api.Controllers;
using Traceability_2203.Common.Domains;
using Traceability_2203.Common.Dtos;

namespace Traceability_2203.Bais.Api.Common
{
    /// <summary>
    /// 配置AutoMapper映射关系
    /// </summary>
    public class AutoMapperProfile : Profile
    {
        public AutoMapperProfile()
        {
            //创建用户新增的映射 由 新增用户的入参 转换 为 用户实体
            CreateMap<UserCreateCommand, Users>();

            //ReverseMap 两个对象可以相互转换
            CreateMap<Users, UserDto>().ReverseMap();

            //两个对象 属性名称不相同 Age==UserAge
            //两个对象 属性 数据类型 不相同 string==>int string==>Datetime
            //从Name 转换为UserName
            CreateMap<People, Person>()
                .ForMember(x => x.UserName, x => x.MapFrom(p => p.Name))
                .ForMember(x => x.UserAge, x => x.MapFrom(p => p.Age))
                .ForMember(x => x.List, x => x.MapFrom(p => p.List))
                //.ForMember(x => x.UserAge, x => x.MapFrom(p => Convert.ToInt32(p.Age)))
                .ReverseMap();
            CreateMap<IDCardDto, IDCardDto2>();


        }
    }
}
